package com.outdoor.server.controller.user;

import com.outdoor.common.result.Result;
import com.outdoor.pojo.dto.UserLoginDTO;
import com.outdoor.pojo.dto.UserPageQueryDTO;
import com.outdoor.pojo.entity.User;
import com.outdoor.pojo.vo.UserLoginVO;
import com.outdoor.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController("userUserController")
@RequestMapping("/user/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 用户微信登录
     * @param userLoginDTO
     * @return
     */
    @PostMapping("/login")
    public Result<UserLoginVO> login(UserLoginDTO userLoginDTO) {
        log.info("login userPageQueryDTO={}", userLoginDTO);
        //微信小程序登录
        User user = userService.wxLogin(userLoginDTO);
        UserLoginVO userLoginVO = UserLoginVO.builder().
                id(user.getId()).
                openid(user.getOpenid())
                .build();
        return Result.success(userLoginVO);
    }

}
